import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MessageService } from '../../core/service';
import { LayoutRourteStatus } from '../../model/status';
import { Title } from '@angular/platform-browser';
import { NzMessageService } from 'ng-zorro-antd';
import { concatMap } from 'rxjs/operators';

@Component({
    selector: 'app-breadcrumb',
    templateUrl: './breadcrumb.component.html',
    styleUrls: ['./breadcrumb.component.scss']
})
export class MyBreadcrumbComponent implements OnInit {
    constructor(
        private _title: Title,
        private msg: MessageService,
        private message: NzMessageService
    ) { }

    private _rb: LayoutRourteStatus = {
        url: 'pages/home',
        isHiddeBreadcrumb: false,
        breadcrumbs: [{ tragetTitle: 'layout', breadcrumbUrl: '/member/center/account/setting' }]
    };
    isShowItem: Boolean = false;
    private searchName = '';

    ngOnInit() {
        this.msg.getMessage().subscribe((e: LayoutRourteStatus) => {
            if (e['url']) {
                this._rb = e;
                // this._rb.breadcrumbs.length > 0 ? this.isShowItem = true : this.isShowItem = false;
                if (e.breadcrumbs) {
                    this._title.setTitle(e.breadcrumbs[e.breadcrumbs.length - 1]['tragetTitle']);
                }
            }
        });
    }
    public change() {
        this.msg.sendMessage(this.searchName);
    }

    startShowMessages(): void {
        this.message.loading('正在读取就诊卡', {
            nzDuration: 2500
        }).onClose!.pipe(concatMap(() => this.message.success('读取成功', { nzDuration: 2500 }).onClose!)).subscribe(() => {
            this.msg.sendMessage('读取就诊卡');
          });
      }
}
